package model;

import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@Entity
@Table(name = "t_sys_role")
public class SysRole implements java.io.Serializable {
	private static final long serialVersionUID = 1688587939591520958L;

	// Fields

	private Integer id;
	private String name;
	private Integer enable;

	private Set<SysModule> modules;

	// Constructors

	/** default constructor */
	public SysRole() {
	}

	/** full constructor */
	public SysRole(Integer enable, String roleName) {
		this.enable = enable;
		this.name = roleName;
	}

	@Column(name = "enable")
	public Integer getEnable() {
		return this.enable;
	}

	// Property accessors
	@Id
	@GeneratedValue
	@Column(name = "id", nullable = false)
	public Integer getId() {
		return this.id;
	}

	@ManyToMany
	@JoinTable(
		name = "t_role_module", 
		joinColumns = @JoinColumn(name = "role_id"), 
		inverseJoinColumns = @JoinColumn(name = "module_id")
	)
	public Set<SysModule> getModules() {
		return modules;
	}

	@Column(name = "role_name", length = 50)
	public String getName() {
		return this.name;
	}

	public void setEnable(Integer enable) {
		this.enable = enable;
	}

	public void setId(Integer roleId) {
		this.id = roleId;
	}

	public void setModules(Set<SysModule> modules) {
		this.modules = modules;
	}

	public void setName(String roleName) {
		this.name = roleName;
	}

}